package com.hifar.utils;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.apache.ibatis.annotations.Param;

/**
 * @author zhuWeiWei
 * @description TODO
 * @date 2025/5/19 15:03
 */
public class SqlWrapperUtils {
    public static String getOrderBy(@Param("ew") Wrapper<?> wrapper) {
        String sqlSegment = wrapper.getSqlSegment();
        if (sqlSegment.toUpperCase().contains("ORDER BY")) {
            return sqlSegment.replaceAll("(?i).*ORDER BY", "ORDER BY");
        }
        return "";
    }


    public static String getWhere(@Param("ew") Wrapper<?> wrapper) {
        String sqlSegment = wrapper.getSqlSegment();
        if (sqlSegment.toUpperCase().contains("ORDER BY")) {
            return sqlSegment.replaceAll("ORDER BY.*", "");
        }
        return sqlSegment;
    }
}
